<template>
	<!-- 商品列表轮播广告 -->
	<view class="content">
		<swiper :style="{height:swiperHeight}" class="swiper" :class="advData.length==1?'on':''" :autoplay="autoplay" :duration="duration" @change="stopChange">
			<swiper-item v-for="(item,index) in advData" :key="index" >
				<view class="swiper-item">
					<view class="swiper-item-img">
						<image :id="'img'+index" @load="(e) => onImageLoad(e, index)" @click="jump(item.link)" :src="item.img" mode="widthFix"></image>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	let app = getApp();
	export default {
		data() {
			return {
				autoplay: true,
				duration: 500,
				navH: 0,
        swiperHeight:375
			}
		},
		props: {
			advData: {
				default: () => []
			},
		},
		mounted() {
			// #ifdef MP
			this.navH = app.globalData.navHeight;
			// #endif
			// #ifndef MP
			this.navH = 80;
			// #endif
		},
		beforeDestroy() {

		},
		methods: {
      onImageLoad(e,index) {
        if(index==0){
          // 获取第一张图片元素真实高度 ==> 然后设置swiper元素高度
          this.$nextTick(() => {
            const query = uni.createSelectorQuery().in(this);
            query.select('#img0').boundingClientRect(data => {
              if (data) {
                this.swiperHeight = data.height+'px'
              }
            }).exec();
          });
        }
      },
			stopChange(){
				if(this.advData.length == 1){
					return false
				}
			},
			jump(url) {
				if(url){
					this.$util.JumpPath(url);
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
	page,
	.content {
		width: 100%;
		height: 100%;
		background-size: 100% auto;
		padding: 0;
	}

	.swiper {
		//background: #FFFFFF;
	}

	.swiper-item {
		width: 100%;
		height: 100%;
		text-align: center;
		position: relative;
		display: flex;
		/* justify-content: center; */
		align-items: flex-end;
		flex-direction: column-reverse
	}

	.swiper-item-img {
		width: 100%;
		height: 100%;
		margin: 0 auto;
	}

	.swiper-item-img image {
		width: 100%;
		height: 100%;
	}

	.jump-over {
		position: absolute;
		height: 45rpx;
		line-height: 45rpx;
		padding: 0 15rpx;
		border-radius: 30rpx;
		font-size: 24rpx;
		color: #b09e9a;
		border: 1px solid #b09e9a;
		z-index: 999;
		right: 30rpx;
	}

	.video-box {
		width: 100vw;
		height: 100vh;

		.vid {
			width: 100%;
			height: 100%;
		}
	}
</style>